package org.yscz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.yscz.webSocket.WebSocket;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author achen
 * @create 2021-08-25 9:26
 */
@RestController
@Slf4j
@Api("折线图推送数据接口")
public class LineController {

    /**
     * webSocket测试
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/sendData")
    @ApiOperation("测试WebSocket一对多接收信息图形变化接口")
    public Map<String, Object> sendData() {
        List<Integer> list = new ArrayList<>();
        list.add(23);
        list.add(2);
        list.add(22);
        list.add(2);
        list.add(22);
        list.add(2);
        list.add(21);

        Map<String, Object> map = new HashMap<>();
        map.put("flag", true);
        map.put("message", "发送成功");
        map.put("data", list);

        return map;
    }

    /**
     * 通过echarts测websocket一对多实现 ---> 前台多个页面会同时改变
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/sendData2", method = RequestMethod.GET)
    @ApiOperation("测试WebSocket一对多接收信息图形变化接口")
    public String sendData2() throws IOException {
        WebSocket.sendInfo("true");
        return "ok";
    }
}
